package com.idc.resource.model;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

/**
 * 验证码信息
 * Created by Administrator on 2017/7/15 0015.
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
public class AuthCodeInfo implements Serializable{
    /** 验证码 */
    private String authCode;
    /** 登录令牌 */
    private String token;
    /** 用户名 */
    private String userId;
    /** 用户id */
    private Long id;

    /**
     * 验证码比较验证
     * @param authCodeInfo 验证码信息
     * @param ignoreCase 是否忽略大小写
     * @return true 一致 false 不一致
     */
    public boolean auth(AuthCodeInfo authCodeInfo,Boolean ignoreCase){
        if(ignoreCase){
            if (authCode != null ? !authCode.toUpperCase().equals(authCodeInfo.authCode.toUpperCase()) : authCodeInfo.authCode != null) return false;
        }else {
            if (authCode != null ? !authCode.equals(authCodeInfo.authCode) : authCodeInfo.authCode != null) return false;
        }
        if (userId != null ? !userId.equals(authCodeInfo.userId) : authCodeInfo.userId != null) return false;
        return id != null ? id.equals(authCodeInfo.id) : authCodeInfo.id == null;
    }

}
